<?php
#+------------------------------------------------------------------
#| 普通的。
#+------------------------------------------------------------------
#| Author:Janmas Cromwell <janmas-cromwell@outlook.com>
#+------------------------------------------------------------------
namespace form\element\form;

use form\element\form\traits\Append;
use form\element\form\traits\Placeholder;
use form\element\form\traits\Prepend;
use form\element\traits\Classes;
use form\element\traits\Css;
use form\element\traits\Id;
use form\element\traits\Js;

class Textarea extends Column
{
    use Prepend, Append, Placeholder, Classes, Id, Css, Js;

    protected $cols      = 0;
    protected $rows      = 0;
    protected $maxLength = 0;
    protected $minLenth  = 0;
    protected $warp      = '';
    protected $value     = '';

    public function value($value)
    {
        $this->value = $value;
        return $this;
    }

    public function cols(int $cols = 0)
    {
        $this->cols = $cols;
        return $this;
    }

    public function rows(int $rows = 0)
    {
        $this->rows = $rows;
        return $this;
    }

    public function min(int $min = 0)
    {
        $this->minLenth = $min;
        return $this;
    }

    public function warp(string $warp)
    {
        $this->warp = $warp;
        return $this;
    }

    public function max(int $max = 0)
    {
        $this->maxLength = $max;
        return $this;
    }

    protected function getCols()
    {
        return $this->cols <= 0 ? '' : 'cols=' . $this->cols;
    }

    protected function getRows()
    {
        return $this->rows <= 0 ? '' : 'cols=' . $this->rows;
    }

    protected function getMinLength()
    {
        return $this->minLenth <= 0 ? '' : 'minlength=' . $this->minLenth;
    }

    protected function getMaxLength()
    {
        return $this->maxLength <= 0 ? '' : 'maxlength=' . $this->maxLength;
    }

    protected function getWarp()
    {
        return empty($this->warp) ? '' : 'warp="' . $this->warp . '"';
    }

    /**
     * @inheritDoc
     */
    protected function normal(): string
    {
        $label = $this->getLabel();
        $id = $this->getId();
        $class = $this->getClass();
        $autocomplete = $this->getAutocomplete();
        $readonly = $this->getReadonly();
        $disabled = $this->getDisabled();
        $required = $this->getRequired();
        $rows = $this->getRows();
        $cols = $this->getCols();
        $minLength = $this->getMinLength();
        $maxLength = $this->getMaxLength();
        $warp = $this->getWarp();
        $tips = $this->getTips();
        $prepend = $this->getPrepend();
        $append = $this->getAppend();
        $labelClass = $this->getLabelClass();

        if (empty($prepend) && empty($append)) {
            $textarea = <<<HTML
<textarea name="$this->name" class="form-control"  id="$id" placeholder="$this->placeholder" aria-describedby="$id" placeholder="$this->placeholder" $autocomplete $readonly $disabled $required $cols $rows $maxLength $minLength $warp >$this->value</textarea>
HTML;
        } else {
            $textarea = <<<HTML
<div class="input-group">
    $prepend
    <textarea name="$this->name" class="form-control"  id="$id" placeholder="$this->placeholder" aria-describedby="$id" placeholder="$this->placeholder" $autocomplete $readonly $disabled $required $cols $rows $maxLength $minLength $warp >$this->value</textarea>
    $append
</div>
HTML;
        }

        return <<<HTML

<div class="$class">
    <label for="$id" class="$labelClass">$label</label>
    $textarea
    $tips
</div>
HTML;
    }

    /**
     * @inheritDoc
     */
    protected function group()
    {
        // TODO: Implement group() method.
    }

    /**
     * @inheritDoc
     */
    protected function grid()
    {
        // TODO: Implement grid() method.
    }

    /**
     * @inheritDoc
     */
    protected function table()
    {
        // TODO: Implement table() method.
    }

    /**
     * @inheritDoc
     */
    protected function vertical()
    {
        // TODO: Implement vertical() method.
    }

    /**
     * @inheritDoc
     */
    protected function inline()
    {

    }

    public function generate()
    {
        return $this->normal();
    }
}